<template>
  <div class="login-panel">
    <h1 class="title">后台管理系统</h1>
    <div class="tabs">
      <el-tabs type="border-card" :stretch="true" v-model="activeName">

        <el-tab-pane  name="account" >
          <template #label>
            <div class="label">
              <el-icon><UserFilled /></el-icon>
              <span class="text">账号登陆</span>
            </div>
          </template>
          <PaneAccount ref="accountRef" />
        </el-tab-pane>

        <el-tab-pane  name="phone">
          <template #label>
            <div class="label">
              <el-icon><Iphone /></el-icon>
              <span class="text">手机登录</span>
            </div>
          </template>
          <PanePhone/>
        </el-tab-pane>

      </el-tabs>
    </div>
    <div class="controls">
      <el-checkbox v-model="isRemPwd" label="记住密码" size="large" />
      <el-link :underline="false">忘记密码</el-link>
    </div>
    <div class="login-btn">
      <el-button type="primary" class="btn" @click="handleLoginBtnClick">立即登录</el-button>
    </div>
  </div>
</template>

<script lang="ts" setup>
import PaneAccount from './pane-account.vue'
import PanePhone from './pane-phone.vue'
import { ref, watch } from 'vue'
import { localCache } from '@/utils/cache';

const activeName = ref('account')

//根据这个状态都记住密码
const isRemPwd = ref<boolean>(localCache.getCache('isRemPwd') ?? false)

watch(isRemPwd, (newValue) => {
  localCache.setCache('isRemPwd', newValue)
})

//通过ref去调用子组件     这里的类型是对象的实例 组件通用写法
const accountRef = ref<InstanceType<typeof PaneAccount>>()

const handleLoginBtnClick = () => {
  if(activeName.value === 'account') {
    //1.首先获取子组件的实例
    accountRef.value?.loginAction(isRemPwd.value)
  }else {
    console.log('手机登录')
  }
  
}

</script>

<style scoped lang="less">
.login-panel {
  width: 350px;
  .title {
    text-align: center;
    margin-bottom: 15px;
  }
  .tabs {
    .label{
      display: flex;
      align-items: center;
      justify-content: center;
      .text {
        margin-left: 5px;
      }
    }
  }
  .controls {
    display: flex;
    justify-content:space-between;
  }
  .login-btn {
    margin-top: 5px;
    .btn {
      width: 100%;
    }
  }
}
</style>